﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

using ModelLayer;

namespace DBLayer
{
    public class DBShowType
    {
        private SqlConnection con;

        public DBShowType()
        {
            con = DBConnection.getInstance().getDBCon();
        }

        /**
         * Get the specific show type from the db, using the show id
         * asd
         * */
        public ShowType GetTypeOnShowId(int show_Id)
        {
            ShowType type = null;
            DateTime date = DateTime.Now;

            SqlDataReader reader = null;

            SqlParameter idParam = new SqlParameter("@show_Id", SqlDbType.Int);
            idParam.Value = show_Id;

            SqlCommand command = new SqlCommand();
            command.Connection = con;
            command.CommandText = "SELECT type, title, description, release FROM ShowType " +
                                    "INNER JOIN show " +
                                    "ON ShowType.id = show.type_Id " +
                                    "WHERE show.id = @show_Id ";
            command.Parameters.Add(idParam);

            try
            {
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    //type = new ShowType(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetDateTime(3));
                    type = new ShowType(reader.GetString(0), reader.GetString(1), reader.GetString(2), date);
                }
                reader.Close();
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }

            return type;
        }
        
    }
}
